/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package documentadorrepositorio.componentes;

import documentadorrepositorio.descritoresArtefatos.DescritorArtefato;
import documentadorrepositorio.descritoresArtefatos.DescritorUtil;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author André
 */
public class PainelListaArtefatos extends javax.swing.JPanel {

    /**
     * Creates new form PainelListaArtefatos
     */
    public PainelListaArtefatos() {
        initComponents();
        incializarTabela();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblArtefato = new javax.swing.JTable();

        tblArtefato.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tblArtefato);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblArtefato;
    // End of variables declaration//GEN-END:variables
    private List<String> tiposArtefatos = null;

    public JTable getTblArtefato() {
        return tblArtefato;
    }
    DefaultTableModel modeloTabela = null;

    private void incializarTabela() {
        modeloTabela = new DefaultTableModel() {
            @Override
            public boolean isCellEditable(int rowIndex, int mColIndex) {
                if (mColIndex <= 3) {
                    return false;
                } else {
                    return true;
                }
            }
        };

        modeloTabela.addColumn("Número");
        modeloTabela.addColumn("Nome");
        modeloTabela.addColumn("Data Criação");
        modeloTabela.addColumn("Review");
        //modeloTabela.addColumn("Tipo");
        modeloTabela.addColumn("Incluir na Documentação");
        this.tblArtefato.setModel(modeloTabela);
        this.tblArtefato.getColumnModel().getColumn(0).setMinWidth(50);
        this.tblArtefato.getColumnModel().getColumn(1).setMinWidth(200);
        this.tblArtefato.getColumnModel().getColumn(2).setMinWidth(80);
        this.tblArtefato.getColumnModel().getColumn(3).setMinWidth(50);
        //this.tblArtefato.getColumnModel().getColumn(4).setMinWidth(120);
        this.tblArtefato.getColumnModel().getColumn(4).setMinWidth(150);

        tiposArtefatos = new ArrayList<>();
        try {
            for (DescritorArtefato descritor : DescritorUtil.obtemDescritores()) {
                tiposArtefatos.add(descritor.obtemTipoArtefato());
            }
        } catch (Exception ex) {
        }
        /*
         DefaultComboBoxModel comboModel = new DefaultComboBoxModel(tiposArtefatos.toArray());
         JComboBox comboBox = new JComboBox();
         comboBox.setModel(comboModel);
         TableColumn colunaTipo = tblArtefato.getColumnModel().getColumn(4);
         colunaTipo.setCellEditor(new DefaultCellEditor(comboBox));*/

        JCheckBox checkBox = new JCheckBox();
        TableColumn colunaDocumentacao = tblArtefato.getColumnModel().getColumn(4);
        colunaDocumentacao.setCellEditor(new DefaultCellEditor(checkBox));
    }
}
